/**
 * Copyright (C) 2007-2011 JUG Events Team <info@jugevents.org>
 *
 * This file is part of JUG Events Web Application.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package it.jugpadova.po;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.Valid;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;
import org.lambico.po.hibernate.EntityBase;

import org.parancoe.plugins.securityevolution.User;

/**
 * @author Enrico Giurin
 * @author Lucio Benfante <lucio.benfante@gmail.com>
 * 
 */
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "email" }) })
@NamedQueries(value = {
		@NamedQuery(name = "Jugger.searchByUsername", query = "from Jugger j where j.user.username = ?"),
		@NamedQuery(name = "Jugger.findByUsernameAndConfirmationCode", query = "from Jugger j where j.user.username = ? and j.confirmationCode = ?"),
		@NamedQuery(name = "Jugger.findByUsernameAndChangePasswordCode", query = "from Jugger j where j.user.username = ? and j.changePasswordCode = ?"),
		@NamedQuery(name = "Jugger.findByPartialJugNameAndCountryAndContinent", query = "from Jugger j where upper(j.jug.name) like upper(?) and upper(j.jug.country.localName) like upper(?) and upper(j.jug.country.continent.name) like upper(?) order by j.jug.name asc"),
		@NamedQuery(name = "Jugger.findAllOrderByUsername", query = "from Jugger j order by j.user.username asc") })
public class Jugger extends EntityBase {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6005123717507782857L;

	private String firstName;

	private String lastName;

	private String email;

	private JUG jug;

	private User user;

	private String confirmationCode;

	private String changePasswordCode;
	
	
	

	public Jugger() {
	}

	@NotBlank
	@Email
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@NotBlank
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	@NotBlank
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@OneToOne(cascade = CascadeType.ALL)
        @Valid
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getConfirmationCode() {
		return confirmationCode;
	}

	public void setConfirmationCode(String confirmationCode) {
		this.confirmationCode = confirmationCode;
	}

	public String getChangePasswordCode() {
		return changePasswordCode;
	}

	public void setChangePasswordCode(String changePasswordCode) {
		this.changePasswordCode = changePasswordCode;
	}

	@ManyToOne
        @Valid
	public JUG getJug() {
		return jug;
	}

	public void setJug(JUG jug) {
		this.jug = jug;
	}


	
}
